/**
 * 2013 2013-5-8
 * @author asdfsadfsdf
 */
package com.surfilter.dp.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.border.EmptyBorder;
import javax.swing.tree.TreePath;

import com.surfilter.dp.context.ContextHolder;
import com.surfilter.dp.util.ViewUtil;
import javax.swing.JButton;
import javax.swing.JToolBar;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;

/**
 * @author asdfsadfsdf
 * 
 */
public class MainWindow extends JFrame {

	private JPanel contentPane;

	private JScrollPane treePanel;

	public MainWindow() {
		setTitle("WebOS开发平台");
		setBackground(Color.WHITE);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 830, 600);

		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu menu = new JMenu("功能");
		menuBar.add(menu);
		final MainWindow window = this;
		JMenuItem menuItem = new JMenuItem("参数配置");
		menuItem.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				new ConfigDialog(window).setVisible(true);
			}
		});
		menu.add(menuItem);

		JMenuItem menuItem_1 = new JMenuItem("代码打包");
		menu.add(menuItem_1);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		BorderLayout borderLayout = new BorderLayout(0, 0);
		contentPane.setLayout(borderLayout);

		ModuleTree moduleTree = new ModuleTree();
		ContextHolder.getInstance().setModuleTree(moduleTree);
		treePanel = new JScrollPane(moduleTree);
		treePanel.setBackground(Color.WHITE);
		contentPane.add(treePanel, BorderLayout.WEST);
		treePanel.setSize(new Dimension(300, 600));
		
		JToolBar toolBar = new JToolBar();
		treePanel.setColumnHeaderView(toolBar);
		final ModuleTree tree = ContextHolder.getInstance().getModuleTree();
		JButton btn_refreshTree = new JButton("刷新数据");
		btn_refreshTree.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tree.refresh();
			}
		});
		toolBar.add(btn_refreshTree);
		
		JButton btn_expandAll = new JButton("展开");
		btn_expandAll.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tree.expandAll();
			}
		});
		toolBar.add(btn_expandAll);
		
		JButton btn_closeAll = new JButton("关闭");
		btn_closeAll.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tree.closeAll();
			}
		});
		toolBar.add(btn_closeAll);

		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		contentPane.add(tabbedPane, BorderLayout.CENTER);

		ModuleDetailPanel panel_1 = new ModuleDetailPanel();
		ContextHolder.getInstance().setModulePanel(panel_1);
		panel_1.setBackground(Color.WHITE);
		tabbedPane.addTab("模块信息", null, panel_1, null);

		ActionPanel panel_2 = new ActionPanel();
		tabbedPane.addTab("Action信息", null, panel_2, null);
		ContextHolder.getInstance().setActionPanel(panel_2);

		CodeGenPanel panel_3 = new CodeGenPanel();
		panel_3.setBackground(Color.WHITE);
		tabbedPane.addTab("代码生成", null, panel_3, null);
		ContextHolder.getInstance().setMainWin(this);
		ViewUtil.toCenter(this);
	}
}
